#include "StdAfx.h"
#include "Shader.h"

namespace rkt
{
	extern GLenum getGLShaderType(ShaderType st);

	bool Shader::create(ShaderType st,const uchar *pBuffer,uint len)
	{
#if RENDER_SYSTEM == RENDER_SYSTEM_GLES2
		assert(0);
		return false;
#else
		glGenProgramsARB(1,&m_id);
		if(m_id)
		{
			m_type = st;
			m_GLType = getGLShaderType(st);
			glBindProgramARB(m_GLType,m_id);
			glProgramStringARB(m_GLType,GL_PROGRAM_FORMAT_ASCII_ARB,len,pBuffer);
			GLenum e = glGetError();
			if(e)
			{
				glDeleteProgramsARB(1,&m_id);
				char str[256];
				sprintf(str,"%s\n",gluErrorString(e));
				Error(str);
				return false;
			}
			return true;
		}
#endif
		return false;
	}

	bool			Shader::compile()
	{
		return true;
	}

	bool Shader::bind()
	{
#if RENDER_SYSTEM == RENDER_SYSTEM_GLES2
		assert(0);
#else
		glBindProgramARB(m_GLType,m_id);
		glEnable(m_GLType);
#endif
		return true;
	}

	void Shader::unbind()
	{
#if RENDER_SYSTEM == RENDER_SYSTEM_GLES2
		assert(0);
#else
		glDisable(m_GLType);
#endif
	}

	void Shader::setParameter4f(const std::string& strPara,float,float,float,float)
	{
	}

	void Shader::setParameter4f(uint index,float x,float y,float z,float w)
	{
#if RENDER_SYSTEM == RENDER_SYSTEM_GLES2
		assert(0);
#else
		glProgramLocalParameter4fARB(m_GLType,index,x,y,z,w);
#endif
	}

	ShaderType Shader::getType()
	{
		return m_type;
	}

	GLuint	Shader::getGLShaderID(){return m_id;}
}